package com.downhometech.productcalculator.activities;

import java.util.ArrayList;

import com.downhometech.productcalculator.controllers.DBAdapter;
import com.downhometech.productcalculator.controllers.ProductController;
import com.downhometech.productcalculator.models.Cart;
import com.downhometech.productcalculator.models.CartItem;
import com.downhometech.productcalculator.models.Product;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.hardware.Camera.Size;
import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.Note;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.webkit.WebSettings.TextSize;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class CartActivityLite extends DefaultActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.cart);

		ProductCalculator application = ((ProductCalculator)getApplicationContext());
		if (!application.isInitted()) { application.resetProductCart(); } 

		Button allProductsByCategoryButton = (Button) findViewById(R.id.FrontScreen_ProductsByCategory);
		allProductsByCategoryButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				showProductsByCategory();
			}
		});

		Button allProductsButton = (Button) findViewById(R.id.FrontScreen_AllProducts);
		allProductsButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				showAllProducts();
			}
		});


		Button goToCartButton = (Button) findViewById(R.id.GoToCart);
		goToCartButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				goToCart();
			}
		});

		Button searchForProduct = (Button) findViewById(R.id.FrontScreen_ProductSearchButton);
		searchForProduct.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				onSearchRequested();
			}
		});

		Button clearCartButton = (Button) findViewById(R.id.ClearCartButton);
		clearCartButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				resetCart();
			}
		});
	}

	private void showProductsByCategory() {
		Intent intent = new Intent(this, ProductListActivity.class);
		intent.putExtra("_id", 0);
		startActivityForResult(intent, 1);	   		   
	}

	private void showAllProducts() {
		Intent intent = new Intent(this, ProductListActivity.class);
		intent.putExtra("_id", -1);
		startActivityForResult(intent, 1);	   		   
	}	

	private void goToCart() {
		Intent intent = new Intent(this, ShowCartActivity.class);
		startActivity(intent);	   		   
	}

	private void resetCart() {
		ProductCalculator application = ((ProductCalculator)getApplicationContext());
		application.resetProductCart();
		AlertDialog alertDialog = new AlertDialog.Builder(CartActivityLite.this).create();
		alertDialog.setTitle(getResources().getString(R.string.ButtonNewOrder));
		alertDialog.setMessage(getResources().getString(R.string.TextNewOrderConfirmation));
		alertDialog.setCancelable(true);
		alertDialog.setButton("OK", new DialogInterface.OnClickListener() 
		{
			public void onClick(DialogInterface dialog, int which)
			{
				dialog.dismiss();
			} 
		});		
		alertDialog.show();
	}







}